import request from "@/utils/request"

export function getBooks(page, size, orderBy = '', search = '') {
    return request({
        method: "get",
        url: '/book/getBooks',
        params: {
            page: page,
            size: size,
            orderBy: orderBy,
            search: search
        }
    })
}

export function getBooksByNum(num = 10) {
    return request({
        method: "get",
        url: '/book/getBooksByNum',
        params: {
            num: num
        }
    })
}

export function getBooksByTypeAndName(page, size, type = '', name = '') {
    return request({
        method: "get",
        url: '/book/getBooksByTypeAndName',
        params: {
            page: page,
            size: size,
            type: type,
            name: name
        }
    })
}

export function getBooksGroupByType() {
    return request({
        method: "get",
        url: '/book/getBooksGroupByType',
    })
}

export function getBookById(id) {
    return request({
        method: "get",
        url: '/book/getBookById',
        params: {
            id: id
        }
    })
}

export function updateBook(periodical) {
    return request({
        method: "post",
        url: '/book/updateBook',
        params: periodical
    })
}

export function addBook(periodical) {
    return request({
        method: "post",
        url: '/book/addBook',
        params: periodical
    })
}

export function deleteBook(id, coverAddress) {
    return request({
        method: "delete",
        url: '/book/deleteBook',
        params: {
            id: id,
            coverAddress: coverAddress,
        }
    })
}

export function deleteBooks(id) {
    return request({
        method: "delete",
        url: '/book/deleteBooks',
        params: {
            id: id
        }
    })
}

export default {
    getBooks,
    getBooksByTypeAndName,
    getBookById,
    getBooksGroupByType,
    addBook,
    deleteBook,
    deleteBooks,
    updateBook,
    getBooksByNum
}